package game

import (
	"FlyFight/Internal/cheese"
	"log"
	"strconv"
)

func (g *Gamer)Delete() error {
	for i,c:=range g.Cheese{
		err:=c.DeleteCheese()
		if err!=nil{
			log.Println("delete cheese error"+strconv.Itoa(g.Uid)+" "+strconv.Itoa(int(i)))
			return err
		}
	}
	return nil
}

func (g *Gamer)ReadySend() {
	g.Conn.WriteJSON(Commend{
		Order: uint8(ready),
		Data: []byte("ready"),
	})
}


func (g *Gamer) AddCheese(T cheese.ChType,x,y int,game *Game) error {
	c,err:=cheese.CreateCheese(g.count,x,y,T)
	if err!=nil{
		log.Println("create cheese error"+strconv.Itoa(g.Uid))
		return err
	}
	g.Cheese[g.count]=c
	g.count++

	return nil
}


func (g *Gamer) SendMessage(data []byte)  {
	err:=g.Conn.WriteJSON(Commend{
		Order: uint8(message),
		Data: data,
	})
	if err!=nil{
		log.Println("send message error",g.Uid)
		log.Println("close connection")
	}
	g.Conn.Close()
}